package com.ruoyi.mqtt.service;

//
//import com.ruoyi.mqtt.config.HbaseTableTemplate;
//import com.ruoyi.mqtt.config.HbaseTemplate;
import com.ruoyi.mqtt.config.HbaseTableTemplate;
import com.ruoyi.mqtt.config.HbaseTemplate;
import com.ruoyi.mqtt.pojo.MqttLogs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * com.mqtt.service
 *
 * @author songshijia
 * @date 2023/11/27
 */
@Service
public class HBaseService {


    @Autowired
    private HbaseTemplate hbaseTemplate;
    @Autowired
    private HbaseTableTemplate hbaseTableTemplate;

    /**
     * HBase添加
     * @author songshijia
     * @date 2023/11/27
     * @param t
     */
    public void save(MqttLogs t){
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.now();
        String format = localDateTime.format(dateTimeFormatter);
        String[] keys = new String[]{"temperature",
        "humidity","vin","topic","time","maxTemperature","minTemperature",
                "maxHumidity","minHumidity"
        };
        String[] values = new String[]{
                String.valueOf(t.getTemperature()), String.valueOf(t.getHumidity()),t.getVin(),t.getTopic(), String.valueOf(t.getTime()),
                String.valueOf(t.getMaxTemperature()), String.valueOf(t.getMinTemperature()),
                String.valueOf(t.getMaxHumidity()), String.valueOf(t.getMinHumidity())
        };
        hbaseTemplate.putData("MqttLogs",format,"info",keys,values);
    }



}
